#ifndef __SMS_BASE_NODE__
#define __SMS_BASE_NODE__

#include "sms_helper.h"
#include "sms_parameter.h"
#include "sms_publisher.h"
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <netdb.h>
#include <thread>
#include <mutex>


namespace sms {


class BaseNode : public std::thread
{

public:
    BaseNode(
        std::string node_name,
        std::string job_name,
        std::string param_file="",
        std::string ip="127.0.0.1",
        int port=9094
    );
    ~BaseNode();
    void release();
    void shutdown();
    void set_param(std::string param_name, nlohmann::json value);
    nlohmann::json get_param(std::string param_name, nlohmann::json default_=0.0);
    bool is_running();
    void start();

    virtual void run();
    virtual void params_changed(nlohmann::json msg);

    sms::Logger logger;
private:
    bool _shutdown;
    std::string _node_name;
    std::string _job_name;
    std::string _ip;
    int _port;
    
    sms::Parameter _sms_param;
    nlohmann::json _global_params;
};


}

#endif
